<?php
/**
 * Created by PhpStorm.
 * User: bigniu
 * Date: 2020-01-25
 * Time: 16:06:44
 */

namespace app\admin\controller;


class Info extends Admin
{

    public function getList(){
        $page = input("page/i", 1) <= 1 ? 1 : input("page/i", 1);
        $type = input("type/i");
        $where=[];
        if($type){
            $where['type']=$type;
        }
        $info =  Db("info")->where($where)->page($page,10)->select();
        if(!$info){
            return error("暂无更多数据");
        }
        return success("成功",$info);
    }
    public function postUpdate(){
        $id=input("id");
        $title = input("title");
        $type = input("type",0)==0?0:1;
        $src = input("src");
        $time =input("time");
        $data = [
            'title'=>$title,
            'type'=>$type,
            "src"=>$src,
            "time"=>$time
        ];
        $res = Db("info")->where(['id'=>$id])->update($data);
        if($res){
            return success("修改成功");
        }
        return error("修改失败");
    }
    public function postAdd(){
        $title = input("title");
        $type = input("type",0)==0?0:1;
        $src = input("src");
        $data = [
            'title'=>$title,
            'type'=>$type,
            "src"=>$src,
            "time"=>date('Y-m-d',time()),
            'create_time'=>TIME
        ];
        $res = Db("info")->insert($data);
        if($res){
            return success("添加成功");
        }
        return error("添加失败");
    }
    public function postDel(){
        $ids = input("ids/a");
        Db("info")->whereIn('id', $ids)->delete();
        return success("删除成功");
    }
}